package com.dylan.历史.领扣;

/**
 * @Auther: ankang
 * @Date: 2019/2/23 01:15
 * @Description:
 */
public class $0062不同路径二 {

//    public static void main(String[] args) {
//        System.out.println(new Solution().uniquePaths(5, 7));
//    }

    static class Solution {
        public int uniquePaths(int[][] obstacleGrid) {

            int m = obstacleGrid.length;
            if(m == 0) {
                return 0;
            }
            int n = obstacleGrid[0].length;
            if(n == 0) {
                return 0;
            }
            int[][] result = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    if (obstacleGrid[i][j] == 0) {
                        if (i == 0 && j == 0) {
                            result[0][0] = 1;
                            continue;
                        }
                        if (i > 0 && obstacleGrid[i - 1][j] == 0) {
                            result[i][j] = result[i][j] + result[i - 1][j];
                        }
                        if (j > 0 && obstacleGrid[i][j - 1] == 0) {
                            result[i][j] = result[i][j] + result[i][j-1];
                        }
                    }
                }
            }
            return result[m-1][n-1];
        }
    }
}
